package com.rede.didiok.common.service.impl;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.rede.didiok.common.constant.conf.SysConf;
import com.rede.didiok.common.constant.global.Constants;
import com.rede.didiok.common.enums.AuditStatusEnum;
import com.rede.didiok.common.enums.UserTagEnum;
import com.rede.didiok.common.service.CommonService;
import com.rede.didiok.common.utils.business.SensitiveUtils;

@Service("commonService")
public class CommonServiceImpl implements CommonService {

    @Autowired
    private SensitiveUtils sensitiveUtils;

    @Override
    public Integer checkIsAudit(HttpServletRequest request, String... contents) {

        for (String content : contents) {
            // 判断是否为广告
            Map<String, String> sensitiveBroadMap = sensitiveUtils.filter(content, true, SysConf.SYS_SENSITIVE_SLOGAN);
            Boolean flg = false;
            if (Integer.parseInt(sensitiveBroadMap.get(SysConf.COUNT)) > Constants.NUM_ZERO) {
                flg = true;
            }
            //查看当前用户 是否是特权用户
            double userTag = 0D;
            if (request.getAttribute(SysConf.USER_TAG) != null) {
                userTag = (double) request.getAttribute(SysConf.USER_TAG);
            }
            if (flg) {
                // 如果是特权用户，免检
                if (userTag <= UserTagEnum.NORMAL_USER.getValue().intValue()) {
                    return AuditStatusEnum.WAIT;
                } else {
                    return AuditStatusEnum.AGREE;
                }
            }
        }
        return AuditStatusEnum.AGREE;
    }

}
